<?php
  if (!defined('baseinfo')) {
    exitdata();
}  
?>
<script src="<?=baseinfo?>/js/vendor/jquery.iuploader-1.0.js"></script>
<script src="<?=baseinfo?>/js/vendor/jquery.Jcrop.min.js"></script>
<script src="<?=baseinfo?>/js/coreadd.js"></script>
<link rel="stylesheet" href="<?=baseinfo?>/css/vendor/jcrop/jquery.Jcrop.min.css" type="text/css" />
<link rel="stylesheet" href="<?=baseinfo?>/css/theme1/coreadd.css" type="text/css" />
<script>
var fidset=0;
function loadfeaturedata(fid)
{
fidset=fid;
$('.tgHdGen.tgCl.clBd2.bdR').removeClass('clSp2');
$('#fidset-'+fid).addClass('clSp2');

$.post(serviceinfo+'loadnewgrouptag', { fid:fid }, function(data) { 

if(data.istag)
{

$('#actv').prop('checked',true);
$('#inactv').prop('checked',false);

}else
{

$('#actv').prop('checked',false);
$('#inactv').prop('checked',true);

}
$('.wrpActvItCell').html('');
if(data.data.length)
{

$.each(data.data, function(key, value) {


addnewdatarow(value.order,value.simgmid,value.simg.newpath,value.imgmid,value.img.newpath,value.tag);



});


}else
{
addnewdatarow();

}


});

}
var rownowdata=1;
function removenewdatarow(rownowdataset)
{
$('#rowsetdata-'+rownowdataset).remove();

}
function addnewdatarow(order,simgmid,simg,imgmid,img,tag)
{
var oderset='';
if(order)
{
oderset=order;
}
var code = '<div id="rowsetdata-'+rownowdata+'" class="itPlg addImgCellTgMn clBd2 bdFull image'+rownowdata+'">\n';
code += '<div class="wrpTl">\n';
code += '<div title="Close" class="btnIco closeTl clBd3 mgBtm10" onclick="removenewdatarow('+rownowdata+')">\n';
code += '<span class="ico icoCloseTl"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="itCellMdMn">\n';
code += '<div class="wrpOrdMdMn clBg5 clTxt2 center">\n';
code += '<span class="txtOrdMn fs03">order</span>\n';
code += '<div class="inpNoFtMn center">\n';
code += '<input type="text" name="order" value="'+oderset+'" class="clBg5 clBd2 bdBtm fs02">\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="bdTgMn clearfix">\n';
code += '<div class="ImgTgMn">\n';
code += '<div class="wrpPlgCellSp clBg5 clBd2 bdFull">\n';
code += '<div class="plgAreaCellSp plgArea"></div>\n';
code += '<div class="wrpTl">\n';
code += '<div class="addTool">\n';
code += '<div title="Browse" class="btnIco addImgTl clBd3 bdBtm uploadbutton">\n';
code += '<span class="ico icoAddImgTl"></span>\n';
code += '<div class="wrpUlFile">\n';
//code += '<input type="file" class="ulFile">\n';
code += '</div>\n';
code += '</div>\n';
code += '<div title="Cloud" class="btnIco addCldTl clBd3 bdBtm cloudbutton">\n';
code += '<span class="ico icoAddCldTl"></span>\n';
code += '</div>\n';
code += '<div title="Link" class="btnIco addLnkTl clBd3 bdBtm linkbutton">\n';
code += '<span class="ico icoAddLnkTl"></span>\n';
code += '</div>\n';
code += '<div title="Remove" class="btnIco btnRmvTl deletebutton">\n';
code += '<span class="ico icoRmvTl"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '<span class="desCellSp clTxt3 fs03">Select an image recommend size 600 x 600 px</span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="inpTgMn">\n';
code += '<div class="hdInpTgMn">\n';
code += '<span class="boldGen clTxt3 fs03">Insert Tag</span>\n';
code += '</div>\n';

var tagset='';
if(tag)
{
tagset=tag;
}

code += '<div class="bdInpTgMn">\n';
code += '<input type="text" name="tag" placeholder="#abc" value="'+tagset+'" class="clBg5 clBd2 fs03 clTxt2">\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';


$('.wrpActvItCell').append(code);
imageset(rownowdata,600,600,150,150);


if(imgmid)
{

$('#rowsetdata-'+rownowdata+' input[name="imgmid[]"]').val(imgmid);
}

if(simgmid)
{

$('#rowsetdata-'+rownowdata+' input[name="simgmid[]"]').val(simgmid);
}


if(simg)
{

$('#rowsetdata-'+rownowdata+' .plgArea').html('<a href="'+img+'" target="_blank"><img width="150" height="150" src="'+simg+'"></a>');
}





rownowdata++;



}

function imageset(rowgnowset,widthset,heightset,widthset2,heightset2)
{
var rownow=1;
var rowgnow=rowgnowset;
 
 $('#feature'+rownow+' .image'+rowgnow+' .uploadbutton').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':rowgnow,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
         
         
         
         getpopupboxresize(widthset,heightset,filelink,setting['originalwidth'],setting['originalheight'],
         
         function(filename2,filelink2,width2,height2,imgmid2){
         var rowgnow2=setting['group'];        
         $('#feature'+rownow+' .image'+rowgnow2+' .plgArea').html('<a target="_blank" href="'+filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="'+heightset2+'" width="'+widthset2+'" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelink[]"]').val(filelink);
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelinkcrop[]"]').val(filelink2);                 
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="fileold[]"]').val(setting.fileold);      
         $("#width-"+setting.id).val(setting.originalwidth);
         $("#height-"+setting.id).val(setting.originalheight);      
         $("#imgmid-"+setting.id).val(setting.imgmid);       
         $("#simgmid-"+setting.id).val(imgmid2);               
         $("#widthcrop-"+setting.id).val(width2);
         $("#heightcrop-"+setting.id).val(height2);    
         
          closepopup();  
         }
         ,setting['imgmid']
         
         );
         //alert(filename);
         }
   });
  
  
   $('#feature'+rownow+' .image'+rowgnow+' .cloudbutton').click(function() {
          //console.log("testdata");
          //var rowgnow3=rowgnow;
          var rowgnow3=rowgnowset;
        //alert("Handler for .click() called.");
          getpopupcloud(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 

        $('#feature'+rownow+' .image'+rowgnow3+' .plgArea').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="'+heightset2+'" width="'+widthset2+'" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);

        closepopup();  

          
          },
          
          
          function(filename,filelink,width,height,imgmid,indexnow){
            
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,widthset
          ,heightset
          
          );

   });
   
   $('#feature'+rownow+' .image'+rowgnow+'  .deletebutton').click(function() {
   
   var rowgnow3=rowgnowset;
   

   $('#feature'+rownow+' .image'+rowgnow3+' .plgArea a').remove();
   
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val('');           
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val('');
   
   
   
    $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val('');
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val('');                                    
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val('');         
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val('');
   
   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .linkbutton').click(function() {
   var rowgnow3=rowgnowset;
   //console.log("test");
   
   getpopuplink(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         $('#feature'+rownow+' .image'+rowgnow3+' .plgArea').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="'+heightset2+'" width="'+widthset2+'" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
        // $.colorbox.close("User added succesfully"); 
        closepopup();  
          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            

            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,widthset
          ,heightset
   );
   
   });
   
    $('#feature'+rownow+' .image'+rowgnow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();

});

}

function savedatarow()
{
var arraynewdata=new Array();
var krow=0;
$( ".addImgCellTgMn" ).each(function( index ) {

            
            var order=$(this).find('input[name="order"]').val();
            var imgmid=$(this).find('input[name="imgmid[]"]').val();
            var simgmid=$(this).find('input[name="simgmid[]"]').val();
            var tag=$(this).find('input[name="tag"]').val();
           
           if(order&&imgmid&&simgmid&&tag)
           {
           arraynewdata[krow]={};

          arraynewdata[krow]['order']=order;
          arraynewdata[krow]['imgmid']=imgmid;
          arraynewdata[krow]['simgmid']=simgmid;
          
          arraynewdata[krow]['tag']=tag;
          krow++;
           
           } 
          

});

if(arraynewdata.length)
{

var active=$('input[name="actv"]:checked').val();

$.post(serviceinfo+'savenewgrouptag', { fid:fidset,data:arraynewdata,active:active }, function(data) { 

boxmsgdata('Suscess');

});
}else
{
boxmsgdata('Please Field All Input');

}


}


loadfeaturedata(<?=$data['featuredata'][0]['fid']?>);

</script>